#include "wxssashwindow.h"
#include <wx/sashwin.h>
#include <prep.h>

namespace {
  wxsRegisterItem<wxsSashWindow> Reg( _T( "SashWindow" ), _T( "窗扇" ), wxsTContainer, _T( "布局" ), 40, false );
  WXS_ST_BEGIN( wxsSashWindowStyles, _T( "wxSW_3D|wxCLIP_CHILDREN" ) )
  WXS_ST_CATEGORY( "wxSashWindow" )
  WXS_ST( wxSW_3D )
  WXS_ST( wxSW_3DSASH )
  WXS_ST( wxSW_3DBORDER )
  WXS_ST( wxSW_BORDER )
  WXS_ST_DEFAULTS()
  WXS_ST_END()
  WXS_EV_BEGIN( wxsSashWindowEvents )
  WXS_EVI( EVT_SASH_DRAGGED, wxEVT_SASH_DRAGGED, wxSashEvent, SashDragged )
  WXS_EV_DEFAULTS()
  WXS_EV_END()
}

wxsSashWindow::wxsSashWindow( wxsItemResData* Data ):
  wxsContainer( Data, &Reg.Info, wxsSashWindowEvents, wxsSashWindowStyles ) {
  mTop    = true;
  mBottom = true;
  mLeft   = true;
  mRight  = true;
}

wxObject* wxsSashWindow::OnBuildPreview( wxWindow* Parent, long Flags ) {
  wxSashWindow *swin = new wxSashWindow( Parent, GetId(), Pos( Parent ), Size( Parent ), Style() );
  SetupWindow( swin, Flags );
  swin->SetSashVisible( wxSASH_TOP,    mTop );
  swin->SetSashVisible( wxSASH_BOTTOM, mBottom );
  swin->SetSashVisible( wxSASH_LEFT,   mLeft );
  swin->SetSashVisible( wxSASH_RIGHT,  mRight );
  AddChildrenPreview( swin, Flags );
  return swin;
}

void wxsSashWindow::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
    case wxsCPP:
      AddHeader( _T( "<wx/sashwin.h>" ), GetInfo().ClassName, 0 );
      Codef( _T( "%C(%W, %I, %P, %S, %T, %N);\n" ) );
      BuildSetupWindowCode();
      AddChildrenCode();
      Codef( _T( "%ASetSashVisible(wxSASH_TOP,    %b);\n" ), mTop );
      Codef( _T( "%ASetSashVisible(wxSASH_BOTTOM, %b);\n" ), mBottom );
      Codef( _T( "%ASetSashVisible(wxSASH_LEFT,   %b);\n" ), mLeft );
      Codef( _T( "%ASetSashVisible(wxSASH_RIGHT,  %b);\n" ), mRight );
      break;
    case wxsUnknownLanguage:
    default:
      wxsCodeMarks::Unknown( _T( "wxsSashWindow::OnBuildCreatingCode" ), GetLanguage() );
  }
}

void wxsSashWindow::OnEnumContainerProperties( M_Code_unused long Flags ) {
  WXS_BOOL( wxsSashWindow, mTop,    _T( "Drag Top" ),    _T( "dragtop" ),    true );
  WXS_BOOL( wxsSashWindow, mBottom, _T( "Drag Bottom" ), _T( "dragbottom" ), true );
  WXS_BOOL( wxsSashWindow, mLeft,   _T( "Drag Left" ),   _T( "dragleft" ),   true );
  WXS_BOOL( wxsSashWindow, mRight,  _T( "Drag Right" ),  _T( "dragright" ),  true );
}

bool wxsSashWindow::OnCanAddChild( M_Code_unused wxsItem* Item, M_Code_unused bool ShowMessage ) {
  return true;
}
